package com.spark.common.model.db

import com.spark.common.ext.append
import io.objectbox.annotation.Convert
import io.objectbox.annotation.Entity
import io.objectbox.annotation.Id
import io.objectbox.converter.PropertyConverter
import java.io.Serializable

@Entity
data class HTSubmitDetailModel(
        @Id
        var _id: Long = 0,
        var sourceprocessorId: String = "",
        var sourceId: String = "",
        var sourceFolder: String = "",
        var sourceDesc: String = "",
        var sourceMoney: String = "",
        var sourceScore: String = "",
        var troubleContent: String = "",
        var fields: String = "",
        var dangerDesc: String = "",
        var handleTime: String = "",
        var handleMan: String = "",
        var actDesc: String = "",
        @Convert(converter = StringListConverter::class, dbType = String::class)
        var imgs: MutableList<String> = mutableListOf()
) : Serializable

class StringListConverter : PropertyConverter<MutableList<String>, String> {
    override fun convertToDatabaseValue(entityProperty: MutableList<String>?): String {
        return entityProperty?.append(",") ?: ""
    }

    override fun convertToEntityProperty(databaseValue: String?): MutableList<String> {
        return if (databaseValue.isNullOrBlank()) mutableListOf()
        else {
            val strList = databaseValue!!.split(",")
            strList.toMutableList()
        }
    }

}